﻿
using System;
using FirebirdSql.Data.FirebirdClient;
using Csla;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Data;

namespace RMSM
{
    [Serializable()]
    public class TaiChinhBO : Csla.BusinessBase<TaiChinhBO>
    {
        #region Business Properties
        private int? _HopDongID = null;
        public int? HopDongID
        {
            get { return this._HopDongID; }
            set { this._HopDongID = value; }
        }

        private string _TenKhachHang = null;
        public string TenKhachHang
        {
            get { return this._TenKhachHang; }
            set { this._TenKhachHang = value; }
        }

        private string _DienThoai = null;
        public string DienThoai
        {
            get { return this._DienThoai; }
            set { this._DienThoai = value; }
        }

        private DateTime? _NgayLamHD = null;
        public DateTime? NgayLamHD
        {
            get { return this._NgayLamHD; }
            set { this._NgayLamHD = value; }
        }

        private double? _TongGiaTriHD = null;
        public double? TongGiaTriHD
        {
            get { return this._TongGiaTriHD; }
            set { this._TongGiaTriHD = value; }
        }

        private double? _SoTienNhan = null;
        public double? SoTienNhan
        {
            get { return this._SoTienNhan; }
            set { this._SoTienNhan = value; }
        }

        private double? _SoTienDatCoc = null;
        public double? SoTienDatCoc
        {
            get { return this._SoTienDatCoc; }
            set { this._SoTienDatCoc = value; }
        }

        private double? _SoTienConLai = null;
        public double? SoTienConLai
        {
            get { return this._SoTienConLai; }
            set { this._SoTienConLai = value; }
        }

        private int _STT0 = 0;
        public int STT0
        {
            get { return this._STT0; }
            set { this._STT0 = value; }
        }
        #endregion Business Properties
        //==========================================================================

        #region Factory Methods
        public void SetIsNew()
        {
            MarkNew();
        }

        public void SetIsOld()
        {
            MarkOld();
        }

        public void SetIsDirty()
        {
            MarkDirty();
        }

        public object GetValue(string fieldName)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            return propInfo.GetValue(this, null);
        }

        public void SetValue(string fieldName, object value)
        {
            PropertyInfo propInfo = this.GetType().GetProperty(fieldName);
            propInfo.SetValue(this, value, null);
            MarkDirty();
        }

        protected override object GetIdValue()
        {
            return -1;
        }

        private TaiChinhBO()
        {
        }

        public TaiChinhBO(FbDataReader dataReader)
        {
            MarkAsChild();
            Fetch(dataReader);
            MarkOld();
        }

        public TaiChinhBO(FbDataReader dataReader, bool isRoot)
        {
            if (!isRoot)
                MarkAsChild();
            Fetch(dataReader);
            MarkOld();
        }

        public static TaiChinhBO NewRootTaiChinhBO()
        {
            return DataPortal.Create<TaiChinhBO>(new RootCriteria());
        }

        internal static TaiChinhBO NewChildTaiChinhBO()
        {
            return DataPortal.Create<TaiChinhBO>(new ChildCriteria());
        }

        public static string GetIDTaiChinhBO()
        {
            return "LoaiTrangPhucID";
        }
        #endregion Factory Methods
        //==========================================================================

        #region Criteria
        [Serializable()]
        public class RootCriteria
        {
            public RootCriteria() { }
        }

        [Serializable()]
        public class ChildCriteria
        {
            public ChildCriteria() { }
        }
        #endregion Criteria
        //==========================================================================

        #region Create
        [RunLocal]
        private void DataPortal_Create(RootCriteria criteria)
        {
        }

        private void DataPortal_Create(ChildCriteria criteria)
        {
            MarkAsChild();
            ValidationRules.CheckRules();
        }

        #endregion Create
        //==========================================================================

        #region Fetch
        [Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Fetch(RootCriteria criteria)
        {
            this.Execute_Fetch(criteria);
        }

        protected void DataPortal_Fetch(string where)
        {
            this.Execute_Fetch(where);
        }

        protected void Execute_Fetch(RootCriteria criteria)
        {
            this.This_Fetch(criteria);
        }

        protected void Execute_Fetch(string where)
        {
            this.This_Fetch(where);
        }

        private void This_Fetch(RootCriteria criteria)
        {

        }

        private void This_Fetch(string where)
        {

        }

        private void Fetch(FbDataReader dataReader)
        {
        }
        #endregion Fetch
        //==========================================================================

        #region Insert
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Insert()
        {
            this.Execute_Insert();
        }

        protected void Execute_Insert()
        {
            this.This_Insert();
        }

        private void This_Insert()
        {
        }
        #endregion Insert
        //==========================================================================

        #region Update
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Update()
        {
            this.Execute_Update();
        }

        protected void Execute_Update()
        {
            this.This_Update();
        }

        private void This_Update()
        {
        }
        #endregion Update
        //==========================================================================

        #region Delete
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            DataPortal_Delete(new RootCriteria());
        }

        private void DataPortal_Delete(RootCriteria criteria)
        {
            this.Execute_Delete(criteria);
        }

        protected void Execute_Delete(RootCriteria criteria)
        {
        }
        #endregion Delete
        //==========================================================================

        #region Internal method
        internal void Insert()
        {
            if (!this.IsDirty) return;
            DataPortal_Insert();
            MarkOld();
        }

        internal void Update()
        {
            if (!this.IsDirty) return;
            DataPortal_Update();
            MarkOld();
        }

        internal void DeleteSelf()
        {
            if (!this.IsDirty) return;
            if (this.IsNew) return;
            DataPortal_Delete(new RootCriteria());
            MarkNew();
        }
        #endregion Internal method
        //==========================================================================
    }
}